<?php

namespace app\admin\controller;

class System extends Common {

    /**
     * @网站日志管理
     */
    public function systemlog() {
        //列表过滤器，生成查询Map对象
        $map = $this->_search("SystemLog");
        if (I('post.content')) {
            $map['content'] = array('like', "%" . I('post.content') . "%");
        }
        if (I('post.username')) {
            $map['username'] = array('like', "%" . I('post.username') . "%");
        }
        if (I('post.ip')) {
            $map['ip'] = I('post.ip');
        }
        $model = M("SystemLog");
        if (!empty($model)) {
            $this->_list($model, $map);
        }
        return $this->fetch();
    }

    /**
     * @删除网站日志（3天前）
     */
    public function systemlog_del() {
        M("SystemLog")->where(array('create_time' => array('lt', time() - 24 * 60 * 60 * 3)))->delete();
        $this->delSuccess("删除成功！");
    }

    /**
     * @节点管理
     */
    public function auth($source = "", $id = "", $pid = "") {

        if (empty($source) && empty($id) && empty($pid)) {
            $list = array();
            $data = M("AuthRule")->field('source,group')->group('source')->select();
            foreach ($data as $key => $value) {
                $child_num = M("AuthRule")->where(array('source' => $value['source']))->count();
                $list[$key]['child_num'] = $child_num;

                $list[$key]['id'] = $key + 1;
                $list[$key]['title'] = $value['group'];
                $list[$key]['name'] = $value['source'];
                $list[$key]['source'] = "导航";
                $list[$key]['group'] = $value['group'];
                $list[$key]['menu'] = 1;
                $list[$key]['sort'] = $key;
            }
            $back = -1;
            $this->assign('list', $list);
        } else {
            $model = D("AuthRule");
            if ($source) {
                $map['source'] = $source;
                $map['pid'] = 0;
                $back = 0;
            } else if ($id) {
                $map['pid'] = $id;
                $back = $id;
            } else if ($pid) {
                $map['id'] = $pid;
                $back = 0;
            }
            $this->_list($model, $map, 'sort', true, false);
        }

        $this->assign('back', $back);
        return $this->fetch();
    }

    /**
     * @节点管理添加
     */
    public function auth_add($source = "", $id = "", $pid = "") {
        if (IS_POST) {
            if ($id) {
                $this->_update("AuthRule", false, false);
            } else {
                $this->_insert("AuthRule", false, false);
            }
        } else {
            if ($source != "" || $pid != "" || $id !== "") {
                if ($source) {
                    $map['source'] = $source;
                } else if ($pid) {
                    $map['id'] = $pid;
                } else if ($id) {
                    $map['id'] = $id;
                }
                $auth = M("AuthRule")->field(true)->where($map)->find();
                $this->assign('auth', $auth);
            } else {
                $auth['status'] = 1;
                $auth['menu'] = 1;
                $this->assign('auth', $auth);
            }
        }

        return $this->fetch();
    }

    /**
     * @节点删除
     */
    public function auth_del($id = '') {
        $this->_delete("AuthRule", $id);
    }

    /**
     * @网站设置
     */
    public function setting() {
        if (IS_POST) {
            $config = I('post.');
            //配置写入文件
            arr2file(APP_PATH, 'site.php', $config);
            $this->sysAdd("执行了【网站更新】操作");
            $this->delSuccess("操作成功");
        } else {
            return $this->fetch();
        }
    }

    /**
     * @邮件服务
     */
    public function email() {
        if (IS_POST) {
            $email = I('post.');
            arr2file(APP_PATH, 'email.php', $email);
            $this->sysAdd("执行了【邮箱服务设置】操作");
            $this->delSuccess("操作成功");
        } else {
            return $this->fetch();
        }
    }

    /**
     * @地区管理
     */
    public function zone() {
        $model = D("Zone");
        $pid = '';
        if (!empty($_REQUEST['id'])) {
            $map['pid'] = $_REQUEST['id'];
            $pid = $_REQUEST['id'];
        } else if (!empty($_REQUEST['pid1'])) {
            $p_zone = $model->where(array('id' => $_REQUEST['pid1']))->find();
            if ($p_zone) {
                $map['pid'] = $p_zone['pid'];
            }
            $pid = $p_zone['pid'];
        } else {
            $map['pid'] = 0;
        }

        if (!empty($model)) {
            $this->_list($model, $map, 'id', true, false);
        }
        $this->assign('pid1', $pid);
        return $this->fetch();
    }

    /*
     * 地区库添加
     */

    public function zone_add($id = '') {
        if (IS_POST) {
            //获取pid
            $_POST['pid'] = $_REQUEST['pzone_id'];

            if ($id) {
                $this->_update("Zone", true, false, true);
            } else {
                $this->_insert("Zone", true, false, true);
            }
        } else {
            if ($id) {
                $zone = D("Zone")->field(true)->where(['id' => $id])->find();
                if ($zone['pid'] > 0) {
                    $p_zone = D("Zone")->field('id,name')->where(['id' => $zone['pid']])->find();
                    $zone['pname'] = $p_zone['name'];
                } else {
                    $zone['pname'] = "顶级";
                }
                $this->assign('zone', $zone);
            } else {
                //严格验证，所以全部附空值
                $zone = array();
                $zone['cid'] = array();
                $zone['pid'] = '';
                $zone['pname'] = '';
                $zone['status'] = 1;
                $zone['m_type'] = 1;
                $this->assign('zone', $zone);
            }
            $cate = M("ZoneCate")->select();
            $this->assign('cate', $cate);
            return $this->fetch();
        }
    }

    /*
     * @地区库删除
     */

    public function zone_del() {
        if (empty($_REQUEST['id'])) {
            $this->iError("提交信息错误，请重新填写。");
        }
        $zoneModel = D("Zone");
        $check = $zoneModel->where(" pid = '" . $_REQUEST['id'] . "'")->count();
        if ($check) {
            $this->iError("该地区有下属地区，请首先删除下属地区在删除该地区。");
        }
        $ret = $zoneModel->where(" id = '" . $_REQUEST['id'] . "'")->delete();
        if ($ret !== false) {
            $this->sysAdd("执行了【删除地区】，地区编号=" . $_REQUEST['id']);
            $this->delSuccess("删除成功！");
        } else {
            $this->iError("删除失败" . $zoneModel->getError());
        }
    }

    /*
     * 地接社导入
     */

    public function location_daoru() {
        //导入该定位
        $result = I('post.locations');
        if (!empty($result)) {
            M('Location')->where('1=1')->delete();
            $resultSet = explode(',', $result);
        }
        foreach ($resultSet as $val) {
            $zt = M('Zone')->where(['id' => $val])->find();
            M('Location')->add($zt);
        }
        $this->ajaxReturn(['message' => '定位成功，您可以进入目的地管理进一步编辑', 'statusCode' => '200', 'closeCurrent' => true, 'forwardConfirm' => '是否自动跳入目的地页？', 'forward' => U('System/goal')]);
    }

    /*
     * 地接社定位
     */

    public function location() {
        //显示location列表多选
        $zone = M("Zone");
        $location = M('location');
        if ($location->count() > 0) {
            $hint = '您已定位，请勿反复操作';
        } else {
            $hint = '您尚未定位，请定位';
        }
        $result = $zone->where(array('pid' => 0))->select();
        $html = '';
        $html .='<input type="hidden" name="locations" data-rule="required" id="j_ztree_menus_setlocation" data-tree="#j_select_tree_setlocation"  size="18" readonly >';
        $html .= '<ul id="j_select_tree_setlocation" data-check-enable="true" class="ztree" data-toggle="ztree" data-expand-all="true" data-on-click="S_NodeClick" data-on-check="S_NodeCheck">';
        foreach ($result as $value) {
            $html .='<li data-id="' . $value['id'] . '" data-pid="' . $value['pid'] . '">' . $value['name'] . '</li>';
            $result1 = $zone->where(array('pid' => $value['id']))->select();
            foreach ($result1 as $v) {
                $html .='<li data-id="' . $v['id'] . '" data-pid="' . $value['id'] . '">' . $v['name'] . '</li>';
                $result2 = $zone->where(array('pid' => $v['id']))->select();
                foreach ($result2 as $val) {
                    $html .='<li data-id="' . $val['id'] . '" data-pid="' . $v['id'] . '">' . $val['name'] . '</li>';
                }
            }
        }
        $html .='</ul>';
        $this->assign('hint', $hint);
        $this->assign('html', $html);
        return $this->fetch();
    }

    /*
     * 目的地管理
     */

    public function goal() {
        $model = D("Location");
        $pid = '';
        if (!empty($_REQUEST['id'])) {
            $map['pid'] = $_REQUEST['id'];
            $pid = $_REQUEST['id'];
        } else if (!empty($_REQUEST['pid1'])) {
            $p_zone = $model->where(array('id' => $_REQUEST['pid1']))->find();
            if ($p_zone) {
                $map['pid'] = $p_zone['pid'];
            }
            $pid = $p_zone['pid'];
        } else {
            $map['pid'] = ['in', '1,2'];
        }

        if (!empty($model)) {
            $this->_list($model, $map, 'id', true, false);
        }
        $this->assign('pid1', $pid);
        return $this->fetch();
    }

    /*
     * 目的地添加
     */

    public function goal_add($id = '') {
        if (IS_POST) {
            //获取pid
            $_POST['pid'] = $_REQUEST['pzone_id'];

            if ($id) {
                $this->_update("Location", true, false, true);
            } else {
                $this->_insert("Location", true, false, true);
            }
        } else {
            if ($id) {
                $zone = D("Location")->field(true)->where(['id' => $id])->find();
                if ($zone['pid'] > 0) {
                    $p_zone = D("Location")->field('id,name')->where(['id' => $zone['pid']])->find();
                    $zone['pname'] = $p_zone['name'];
                } else {
                    $zone['pname'] = "顶级";
                }
                $this->assign('zone', $zone);
            } else {
                //严格验证，所以全部附空值
                $zone = array();
                $zone['cid'] = array();
                $zone['pid'] = '';
                $zone['pname'] = '';
                $zone['status'] = 1;
                $zone['zhuozhong'] = 0;
                $zone['m_type'] = 1;
                $this->assign('zone', $zone);
            }
            $cate = M("ZoneCate")->select();
            $this->assign('cate', $cate);
            return $this->fetch();
        }
    }

    /*
     * @目的地删除
     */

    public function goal_del() {
        if (empty($_REQUEST['id'])) {
            $this->iError("提交信息错误，请重新填写。");
        }
        $zoneModel = D("Location");
        $check = $zoneModel->where(" pid = '" . $_REQUEST['id'] . "'")->count();
        if ($check) {
            $this->iError("该地区有下属地区，请首先删除下属地区在删除该地区。");
        }
        $ret = $zoneModel->where(" id = '" . $_REQUEST['id'] . "'")->delete();
        if ($ret !== false) {
            $this->sysAdd("执行了【删除地区】，地区编号=" . $_REQUEST['id']);
            $this->delSuccess("删除成功！");
        } else {
            $this->iError("删除失败" . $zoneModel->getError());
        }
    }

    /*
     * @幻灯片管理
     */

    public function slide() {
        $map = $this->_search("Slide");
        $model = M("Slide");
        if (!empty($model)) {
            $this->_list($model, $map);
        }
        return $this->fetch();
    }

    /*
     * @幻灯片添加
     */

    public function slide_add($id = '') {
        if (IS_POST) {
            if ($id) {
                $this->_update("Slide", false, false);
            } else {
                $this->_insert("Slide", false, false);
            }
        } else {
            if ($id) {
                $nc = M("Slide")->field(true)->find($id);
                $this->assign('slide', $nc);
            } else {
                $nc['type'] = '';
                $this->assign('slide', $nc);
            }
            return $this->fetch();
        }
    }

    /*
     * @幻灯片删除
     */

    public function slide_del($id = '') {
        $this->_delete("Slide", $id);
    }

    /*
     * @ 关于我们
     */

    public function aboutus() {
        $map = $this->_search("Aboutus");
        $model = D("Aboutus");
        if (!empty($model)) {
            $this->_list($model, $map, 'id');
        }
        return $this->fetch();
    }

    /*
     * @ 关于我们添加
     */

    public function aboutus_add($id = '') {
        if (IS_POST) {
            if ($id) {
                $this->_update("Aboutus", false, true);
            } else {
                $this->_insert("Aboutus", false, true);
            }
        } else {
            if ($id) {
                $nc = M("Aboutus")->field(true)->find($id);
                $this->assign('aboutus', $nc);
            } else {
                
            }
            return $this->fetch();
        }
    }

    /*
     * @ 关于我们删除
     */

    public function aboutus_del($id = '') {
        $this->_delete("Aboutus", $id);
    }

    /*
     * @ 路由管理
     */

    public function route() {
        if (IS_POST) {
            $route = array();
            $diy_route = array_filter(explode("\n", $_POST['route']));
            if (!empty($diy_route)) {
                foreach ($diy_route as $key => $value) {
                    $value = explode("=>", str_replace(array("\r\n", "\r", "\n", " "), "", $value));
                    //禁止手动输入路由规则
                    //$rule[$value[0]] = $value[1];
                }
            }
            //配置写入文件
            //新闻
            $newsCategory = D("NewsCategory")->field('id,write_string')->select();
            foreach ($newsCategory as $value) {
                if ($value['write_string']) {
                    $rule['tours/' . $value['write_string']] = "tours/news/newslist?write_string=" . $value['write_string'];
                    $rule['tours/' . $value['write_string'] . "/:p"] = "tours/news/newslist?write_string=" . $value['write_string'];
                }
            }
            $rule["tours/news/:id"] = array('tours/news/show_news', ['ext' => 'html'], ['id' => '\d+']);
            //新闻手机端
            foreach ($newsCategory as $value) {
                if ($value['write_string']) {
                    $rule['mobile/' . $value['write_string']] = "mobile/news/newslist?write_string=" . $value['write_string'];
                    $rule['mobile/' . $value['write_string'] . "/:p"] = "mobile/news/newslist?write_string=" . $value['write_string'];
                }
            }
            $rule["mobile/news/:id"] = array('mobile/news/show_news', ['ext' => 'html'], ['id' => '\d+']);
            //$rule["mobile/news/:id"] = array('mobile/news/show_news', ['ext' => 'html'], ['id' => '\d+']);
            //目的地
            /* for ($i = 1; $i < 6; $i++) {
              $daozone[$i] = C('site.d' . $i . '_id');
              } */
            $zoneModel = D('location');
            // $daozone_list = implode(',', $daozone);
            $where['status'] = 1;
            $zonelist = $zoneModel->field('id,write_string')->where($where)->select();
            foreach ($zonelist as $value) {
                if ($value['write_string']) {
                    $rule['tours/' . $value['write_string'] . '$'] = "tours/linesort/line_show?id=" . $value['id'];
                    $rule['tours/' . $value['write_string'] . '/:type/:label/:day$'] = array("tours/linesort/line_show?id=" . $value['id'], [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+']);
                    $rule['tours/' . $value['write_string'] . "/:type/:label/:day/:min_price/:max_price/:order/:sort$"] = array("tours/linesort/line_show?id=" . $value['id'], [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+', 'min_price' => '\d+', 'max_price' => '\d+', 'order' => '\d+', 'sort' => '\d+']);
                    $rule['tours/' . $value['write_string'] . "/:type/:label/:day/:min_price/:max_price/:order/:sort/:p$"] = array("tours/linesort/line_show?id=" . $value['id'], [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+', 'min_price' => '\d+', 'max_price' => '\d+', 'order' => '\d+', 'p' => '\d+']);
                    $rule['mobile/' . $value['write_string'] . '$'] = "mobile/linesort/line_show?id=" . $value['id'];
                    $rule['mobile/' . $value['write_string'] . '/:p$'] = array("mobile/linesort/line_show?id=" . $value['id'], [], [ 'p' => '\d+']);
                }
            }
            $rule['mobile/mudidi$'] = "mobile/linesort/mudidi";

            //标签
            //获取tours中实际使用了的标签
            $label_string = '';
            $labels = M('Tours')->where(array('ischecked' => 1))->field('labels')->select();
            foreach ($labels as $key => $v) {
                if ($labels != '') {
                    $label_string .=ltrim($v['labels'], ",");
                }
            }
            $labels_arr = explode(',', $label_string);
            $labels_arr = array_unique($labels_arr);
            foreach ($labels_arr as $k => $value) {
                $rule['tours/tours/' . $value . '$'] = "tours/linesort/label_show?id=" . $value;
                $rule['tours/tours/' . $value . '/:type/:label/:day$'] = array("tours/linesort/label_show?id=" . $value, [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+']);
                $rule['tours/tours/' . $value . "/:type/:label/:day/:min_price/:max_price/:order/:sort$"] = array("tours/linesort/label_show?id=" . $value, [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+', 'min_price' => '\d+', 'max_price' => '\d+', 'order' => '\d+', 'sort' => '\d+']);
                $rule['tours/tours/' . $value . "/:type/:label/:day/:min_price/:max_price/:order/:sort/:p$"] = array("tours/linesort/label_show?id=" . $value, [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+', 'min_price' => '\d+', 'max_price' => '\d+', 'order' => '\d+', 'p' => '\d+']);
            }


            //一日游二日游-----五日游
            $rule["tours/yiriyou$"] = "tours/linesort/day?day=1";
            $rule["tours/yiriyou/:type/:label/:day$"] = array('tours/linesort/day', [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+']);
            $rule["tours/yiriyou/:type/:label/:day/:min_price/:max_price/:order/:sort$"] = array('tours/linesort/day', [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+', 'min_price' => '\d+', 'max_price' => '\d+', 'order' => '\d+', 'sort' => '\d+']);
            $rule["tours/yiriyou/:type/:label/:day/:min_price/:max_price/:order/:sort/:p$"] = array('tours/linesort/day', [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+', 'min_price' => '\d+', 'max_price' => '\d+', 'order' => '\d+', 'p' => '\d+']);

            $rule["tours/erriyou$"] = "tours/linesort/day?day=2";
            $rule["tours/erriyou/:type/:label/:day$"] = array('tours/linesort/day', [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+']);
            $rule["tours/erriyou/:type/:label/:day/:min_price/:max_price/:order/:sort$"] = array('tours/linesort/day', [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+', 'min_price' => '\d+', 'max_price' => '\d+', 'order' => '\d+', 'sort' => '\d+']);
            $rule["tours/erriyou/:type/:label/:day/:min_price/:max_price/:order/:sort/:p$"] = array('tours/linesort/day', [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+', 'min_price' => '\d+', 'max_price' => '\d+', 'order' => '\d+', 'p' => '\d+']);

            $rule["tours/sanriyou$"] = "tours/linesort/day?day=3";
            $rule["tours/sanriyou/:type/:label/:day$"] = array('tours/linesort/day', [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+']);
            $rule["tours/sanriyou/:type/:label/:day/:min_price/:max_price/:order/:sort$"] = array('tours/linesort/day', [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+', 'min_price' => '\d+', 'max_price' => '\d+', 'order' => '\d+', 'sort' => '\d+']);
            $rule["tours/sanriyou/:type/:label/:day/:min_price/:max_price/:order/:sort/:p$"] = array('tours/linesort/day', [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+', 'min_price' => '\d+', 'max_price' => '\d+', 'order' => '\d+', 'p' => '\d+']);

            $rule["tours/siriyou$"] = "tours/linesort/day?day=4";
            $rule["tours/siriyou/:type/:label/:day$"] = array('tours/linesort/day', [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+']);
            $rule["tours/siriyou/:type/:label/:day/:min_price/:max_price/:order/:sort$"] = array('tours/linesort/day', [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+', 'min_price' => '\d+', 'max_price' => '\d+', 'order' => '\d+', 'sort' => '\d+']);
            $rule["siriyou/:type/:label/:day/:min_price/:max_price/:order/:sort/:p$"] = array('tours/linesort/day', [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+', 'min_price' => '\d+', 'max_price' => '\d+', 'order' => '\d+', 'p' => '\d+']);

            $rule["tours/wuriyou$"] = "tours/linesort/day?day=5";
            $rule["tours/wuriyou/:type/:label/:day$"] = array('tours/linesort/day', [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+']);
            $rule["tours/wuriyou/:type/:label/:day/:min_price/:max_price/:order/:sort$"] = array('tours/linesort/day', [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+', 'min_price' => '\d+', 'max_price' => '\d+', 'order' => '\d+', 'sort' => '\d+']);
            $rule["tours/wuriyou/:type/:label/:day/:min_price/:max_price/:order/:sort/:p$"] = array('tours/linesort/day', [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+', 'min_price' => '\d+', 'max_price' => '\d+', 'order' => '\d+', 'p' => '\d+']);
            $rule["tours/tianshu$"] = array('tours/linesort/day', [], ['type' => '0', 'label' => '0', 'day' => '0']);
            $rule["tours/tianshu/:type/:label/:day$"] = array('tours/linesort/day', [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+']);
            $rule["tours/tianshu/:type/:label/:day/:min_price/:max_price/:order/:sort$"] = array('tours/linesort/day', [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+', 'min_price' => '\d+', 'max_price' => '\d+', 'order' => '\d+', 'sort' => '\d+']);
            $rule["tours/tianshu/:type/:label/:day/:min_price/:max_price/:order/:sort/:p$"] = array('tours/linesort/day', [], ['type' => '\d+', 'label' => '\d+', 'day' => '\d+', 'min_price' => '\d+', 'max_price' => '\d+', 'order' => '\d+', 'p' => '\d+']);

            $rule["mobile/yiriyou$"] = "mobile/linesort/day?day=1";

            $rule["mobile/yiriyou/:p$"] = array('mobile/linesort/day?day=1', [], ['p' => '\d+']);
            $rule["mobile/erriyou$"] = "mobile/linesort/day?day=2";
            $rule["mobile/erriyou/:p$"] = array('mobile/linesort/day?day=2', [], ['p' => '\d+']);
            $rule["mobile/sanriyou$"] = "mobile/linesort/day?day=3";
            $rule["mobile/sanriyou/:p$"] = array('mobile/linesort/day?day=3', [], ['p' => '\d+']);
            $rule["mobile/siriyou$"] = "mobile/linesort/day?day=4";
            $rule["mobile/siriyou/:p$"] = array('mobile/linesort/day?day=4', [], ['p' => '\d+']);
            $rule["mobile/wuriyou$"] = "mobile/linesort/day?day=5";
            $rule["mobile/wuriyou/:p$"] = array('mobile/linesort/day?day=5', [], ['p' => '\d+']);

            //线路
            $rule["tours/xianlu/:id$"] = array('tours/line/index', [], ['id' => '\d+']);
            $rule["tours/xianlu/:id/:p$"] = array('tours/line/index', [], ['id' => '\d+', 'p' => '\d+']);
            $rule["mobile/:id$"] = array('mobile/line/index', [], ['id' => '\d+']);
            $rule['mobile/linebook/:id$'] = array('mobile/line/book', [], ['id' => '\d+']);
            //线路预订
            $rule["tours/book/proc_one/:ordertime/:price_id/:adults/:childs/:id"] = "tours/line/book?step=1";
            $rule["tours/book/proc_success/:id"] = "tours/line/book?step=2";

            //主题
            $theme = D("ToursTheme");
            $themelist = $theme->field("id,write_string")->where(array('status' => 1))->select();
            foreach ($themelist as $value) {
                if ($value['write_string']) {
                    $rule['tours/theme/' . $value['write_string'] . '$'] = "tours/linesort/theme?id=" . $value['id'];
                    $rule['tours/theme/' . $value['write_string'] . '/:p$'] = array('tours/linesort/theme?id=' . $value['id'], [], ['p' => '\d+']);
                }
            }
            $rule["tours/theme$"] = "tours/linesort/theme_index";
            //热门景点
            $rule["tours/sirendingzhi$"] = "tours/linesort/srdz";
            $theme = M("Jingdian");
            $themelist = $theme->field("id,write_string")->where(array('status' => 1))->select();
            foreach ($themelist as $value) {
                if ($value['write_string']) {
                    $rule['tours/jingdian/' . $value['write_string']] = "tours/linesort/jingdian?id=" . $value['id'];
                }
            }
            $rule["tours/jingdian$"] = "tours/linesort/jingdian_index";
            //支付中心
            $rule["tours/zhifu$"] = "tours/company/zhifu";
            //行程打印
            $rule["tours/dayin/:id"] = array('tours/line/print_trip', ['ext' => 'html'], ['id' => '\d+']);
            //关于我们
            $rule["tours/about/:id"] = array('tours/company/about', ['ext' => 'html'], ['id' => '\d+']);
            $rule["mobile/about/:id"] = array('mobile/company/aboutus', [], ['id' => '\d+']);
            //线路搜索
            $rule["tours/search$"] = "tours/linesort/search_key";
            $rule["tours/search/:keyword/:p$"] = array('tours/linesort/search_key', [], ['keyword' => '\w+', 'p' => '\d+']);
            $rule["mobile/search$"] = "mobile/linesort/search_key";
            $rule["mobile/search/:keyword/:p$"] = array('mobile/linesort/search_key', [], ['keyword' => '\w+', 'p' => '\d+']);
            arr2file(APP_PATH, 'route.php', $rule);
            $this->sysAdd("执行了【路由更新】操作");
            $this->delSuccess("操作成功");
        } else {
            //默认规则
            $rule = C('route');

            $route = '';
            foreach ($rule as $key => $value) {
                $values = '';
                if (is_array($value)) {
                    foreach ($value as $k => $v) {
                        if (is_array($v)) {
                            foreach ($v as $ke => $val) {

                                if (is_array($val)) {
                                    foreach ($val as $kes => $vals) {
                                        $values .= '[' . $kes . '=>' . $vals . ']';
                                    }
                                } else {
                                    $values .= '[' . $ke . '=>' . $val . ']';
                                }
                            }
                        } else {
                            $values .= '[' . $v . ',';
                        }
                    }
                    $route .=$key . "=>" . $values . "]\n";
                } else {
                    $route .=$key . "=>" . $value . "\n";
                }
            }
            $this->assign('route', $route);
            return $this->fetch();
        }
    }

}
